$(function(){

    //当这个cookie存在时就不用再登陆了
    startchek();
		function startchek(){
     if($.cookie("rmbUser") == "true"){
        window.location.href='index.html';
      }
  }

//获取cookie的信息并检测是否符合账号的规格
    function getcookie(){
			var strCookie = document.cookie;
            var arrCookie = strCookie.split("; ");
            for(var i = 0; i < arrCookie.length; i++){
                var arr = arrCookie[i].split("=");
             	var username = arr[0];
              	var regPhone = /^1([3578]\d|4[57])\d{8}$/; 
             	if(regPhone.test(username) == true){
             		checkAccount(username);	
             	}
            }
        }    
            function checkAccount(username){
       			var str = $.cookie(username);
       			var strJson = eval('('+ str +')');
       			var username = Number(strJson[0].username);
       			var password = strJson[0].password;
       			if($('#account').val() == username && $('#password').val() == password){
               if ($('[name="remember"]').prop('checked')==true) {
                   $.cookie("rmbUser","true",{expires:10,path:'/'})
              }
       				alert("登录成功");
       				window.location.href='index.html';
       			}else{
       				alert("密码或账号错误");
       			}
            }

                $('#login-btn').click(function(){
                	getcookie();
              	})
})